<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教练信息修改</title>
    <link rel="stylesheet" href="../../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../../css/okadmin.css">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>教练信息修改</legend>
</fieldset>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">I&#12288;&#12288;&#12288;D</label>
                        <div class="layui-input-block ">
                            <input type="text" id="coachId" name="coachId" lay-verify="required"
                                   style="background-color: #dcdcdc" disabled
                                   placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">姓&#12288;&#12288;名</label>
                        <div class="layui-input-block ">
                            <input id="fullname" name="fullname" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder="" lay-verify="required" autocomplete="off">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">电&#12288;&#12288;话</label>
                        <div class="layui-input-block ">
                            <input id="phone" name="phone" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder="" autocomplete="off">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">性&#12288;&#12288;别</label>
                        <div class="layui-input-block">
                            <input type="radio" name="agender" id="agender0" value="0" title="女" checked>
                            <input type="radio" name="agender" id="agender1" value="1" title="男">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">邮&#12288;&#12288;箱</label>
                        <div class="layui-input-block ">
                            <input id="email" name="email" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder="" autocomplete="off">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">车&#12288;&#12288;辆</label>
                        <div class="layui-input-block ">
                            <select name="vehicle" id="vehicle" style="float: left;position: relative;" lay-search>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">教学科目</label>
                        <div class="layui-input-block ">
                            <select name="teachingStage" id="teachingStage" style="float: left;position: relative;"
                                    lay-verify="teachingStage">
                                <option value="1">科目一</option>
                                <option value="2">科目二</option>
                                <option value="3">科目三</option>
                                <option value="4">科目四</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">是否被选</label>
                        <div class="layui-input-block ">
                            <select name="isStartChoice" id="isStartChoice" style="float: left;position: relative;"
                                    lay-verify="isStartChoice">
                                <option value="0">未开始被选</option>
                                <option value="1">开始被选</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">最大学员数</label>
                        <div class="layui-input-block ">
                            <select name="choiceCountMax" id="choiceCountMax" style="float: left;position: relative;"
                                    lay-verify="choiceCountMax">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-list" lay-submit id="update">
                            更改
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../../lib/layui/layui.js"></script>
<script src="../../js/jquery.min.js"></script>
<script src="../../js/application.js"></script>
<script>
    var vehicleId="";
    var vehicleName="";
    function init(){
        htmlSetValue("coachId")
        htmlSetValue("fullname")
        htmlSetValue("phone")
        htmlSetValue("agender",function(value){
            if(value=="0"){
                $("#agender0").attr("checked","checked")
                $("#agender1").removeAttr("checked")
            }else{
                $("#agender1").attr("checked","checked")
                $("#agender0").removeAttr("checked")
            }
        })
        htmlSetValue("vehicleId",function(v){
            vehicleId=v
        })
        htmlSetValue("vehicleName",function(v){
            vehicleName=v
        })
        if(vehicleId!=""){
            var option = "<option value='" + vehicleId + "'>" + vehicleName + "</option>";
            $("#vehicle").append(option);
        }else{
            var option = "<option value=''>暂不选择</option>";
            $("#vehicle").append(option);
        }
        htmlSetValue("email")
        htmlSetValue("teachingStage",function(v){
            var value="option[value="+v+"]";
            $("#teachingStage").find(value).attr('selected',true)
        })
        htmlSetValue("isStartChoice",function(v){
            v=v=="true"?1:0;
            var value="option[value="+v+"]";
            $("#isStartChoice").find(value).attr('selected',true)
        })
        htmlSetValue("choiceCountMax",function(v){
            var value="option[value="+v+"]";
            $("#choiceCountMax").find(value).attr('selected',true)
        })
    }


    layui.use(['form','layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        init()
        form.render();
        myAjax(mainUri + '/vVehicle/selects', {page: -1,isFree:1}, function (datas) {
            var list = datas['data'];
            var option;
            for (var i = 0; i < list.length; i++) {
                {
                    option += "<option value='" + list[i]['vehicleId'] + "'>" + list[i]['vehicleName'] + "</option>";
                }
            }
            $("#vehicle").append(option);
            form.render();
        })

        $("#update").on('click',function(){
            if($('#coachId').val()==""||$('#fullname').val()==""){
                return;
            }
            var teachingStage = $("#teachingStage").find("option:checked").val();//教学科目
            var isStartChoice = $("#isStartChoice").find("option:checked").val();//是否被选
            var choiceCountMax = $("#choiceCountMax").find("option:checked").val();//最大学员数
            var vehicle = $("#vehicle").find("option:checked").val();//车辆
            var msg="确定修改id为 "+$('#coachId').val()+"的教练的信息?";
            var data={coachId:$('#coachId').val(),fullname:$('#fullname').val(),phone:$('#phone').val(),email:$('#email').val(),
                agender:$('input[name="agender"]:checked').val(),teachingStage:teachingStage,isStartChoice:isStartChoice,choiceCountMax:choiceCountMax,vehicleId:vehicle,vehicleOldId:vehicleId};
            if(vehicle==vehicleId){
                data["vehicleId"]=""
            }
            layer.confirm(msg, function (index) {
                showloading(true)
                myAjax(mainUri + "/coach/update", data, function (d) {
                    if (d['code'] == '0') {
                        layer.msg(d['msg'], {
                            icon: 1, time: 2000, end: function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index);
                            }
                        })
                    } else {
                        alert(d['msg'])
                    }
                })
                showloading(false)
            })
        })
    });
</script>
</html>